package com.hbnu.controller;

import com.hbnu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.WebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        return "/index.jsp";
    }

    @RequestMapping("/demo1")
    @ResponseBody
    public void demo1(@RequestParam String name,String address){
        System.out.println(name);
        System.out.println(address);
    }


    @RequestMapping("/demo2")
    @ResponseBody
    public void demo2(@ModelAttribute User user){
        System.out.println(user);
    }
    @RequestMapping("/demo3/{name}/{address}")
    @ResponseBody
    public void demo3(@PathVariable("name") String username, @PathVariable String address){
        System.out.println(username);
        System.out.println(address);
    }

    @RequestMapping("/demo4")
    @ResponseBody
    public void demo4(WebRequest webRequest){
        System.out.println(webRequest.getContextPath());
        Map<String,String[]> maps = webRequest.getParameterMap();
        for (String s:maps.keySet()){
            System.out.print(s + "----->");
            String[] values = maps.get(s);
            for (String ss:values){
                System.out.print(ss);
            }
            System.out.println();
        }
    }
    @RequestMapping("/demo5")
    @ResponseBody
    public void demo5(HttpServletRequest req, HttpServletResponse resp){

    }
}
